$(document).ready(function() {
   web.main();
});
var com={
	/*
	 * 设置动画样式
	 */
	animatStyle : function(style,type){
		return type==1?"animation:"+style+"; -webkit-animation:"+style+";":{"animation":style,"-webkit-animation":style};
	},
	 /*
	 * 延时加载图片
	 */
	loadImg : function(){
		var imgLen=$("[name='load']").length,bgLen=$("[name='loadbg']").length,swich=true,setTimes="",$this="";
		
		$(window).ready(function(){
			if(swich) scrolls();
		});
		
		$(window).scroll(function(){
			if(swich) scrolls();
		});
		
		setTimes=setTimeout(function(){
			if(swich) loads();
		},2500);
		
		function scrolls(){
			if($(document).scrollTop()>100) loads();
		}
		
		function loads(){
			if(setTimes) clearTimeout(setTimes);
			
			for(var i=0;i<bgLen;i++){
				$this=$("[name='loadbg']").eq(i);
				if($this.data("bg")) $this.addClass($this.data("bg"));
			}
			
			swich=false;
		}
	}
}
var web={
	main : function(){
		web.init();
		web.appAnimate();
		web.resize();
		com.loadImg();
	},
	init : function(){
		this.box_1_Id=$("#box_1");
		this.tit_1_Id=$("#tit_1");
		this.img_1_Id=$("#img_1");
		this.tit_2_Id=$("#tit_2");
		this.img_2_Id=$("#img_2");
		this.tit_3_Id=$("#tit_3");
		this.img_3_Id=$("#img_3");
		this.tit_4_Id=$("#tit_4");
		this.img_4_Id=$("#img_4");
		this.tit_5_Id=$("#tit_5");
		this.img_5_Id=$("#img_5");
		this.tit_6_Id=$("#tit_6");
		this.img_6_Id=$("#img_6");
		this.tit_7_Id=$("#tit_7");
		this.img_7_Id=$("#img_7");
		this.tit_8_Id=$("#tit_8");
		this.img_8_Id=$("#img_8");
		
		this.iosVer_Id=$("#iosVer");
		this.iosDevBtn_Id=$("#iosDevBtn");
		this.andrBtn_Id=$("#andrBtn");
		this.aniVer_Id=$("#aniVer");
		this.andrDevBtn_Id=$("#andrDevBtn");
		this.aniDownBtn_Id=$("#aniDownBtn");
		this.andrDevDownBtn_Id=$("#andrDevDownBtn");
		
		this.data={
			swich_1 : true,
			swich_2 : true,
			swich_3 : true,
			swich_4 : true,
			swich_5 : true,
			swich_6 : true,
			swich_7 : true,
			swich_8 : true
		}
	},
	/*
	 * 自适应屏幕大小
	 */
	resize : function(){
		var width=0;
		
		$(window).ready(function(){
			res();
		});
		
		$(window).resize(function(){
			res();
		});
		
		function res(){
			width=$(this).width();
			
			web.box_1_Id.css({"transform":(width<=1160?"scale(0.8)":"scale(1)")});
			web.tit_2_Id.css({"left":(width<=1160?380+115:380)});
			web.tit_3_Id.css({"left":(width<=1160?1080-115:1080)});
			web.tit_4_Id.css({"left":(width<=1160?410+115:410)});
			web.tit_5_Id.css({"left":(width<=1160?1120-90:1120)});
			web.tit_6_Id.css({"left":(width<=1160?480+115:480)});
			web.tit_7_Id.css({"left":(width<=1160?1080-115:1080)});
		}
	},
	appAnimate : function(){
		var width=0,height=0,scrollTop=0,top=0;
		
		$(window).scroll(function(){
			scrollTop=$(document).scrollTop();
			height=$(window).height();
			
			if(web.data.swich_2) res(web.tit_2_Id,200,res_2);
			if(web.data.swich_3) res(web.tit_3_Id,200,res_3);
			if(web.data.swich_4) res(web.tit_4_Id,200,res_4);
			if(web.data.swich_5) res(web.tit_5_Id,200,res_5);
			if(web.data.swich_6) res(web.tit_6_Id,200,res_6);
			if(web.data.swich_7) res(web.tit_7_Id,200,res_7);
			if(web.data.swich_8) res(web.tit_8_Id,200,res_8);
		});
		
		web.tit_1_Id.css(com.animatStyle("tit_1 1.6s cubic-bezier(.1,0,.04,1) forwards 0.2s"));
		web.img_1_Id.css(com.animatStyle("img_1 1.6s cubic-bezier(.1,0,.04,1) forwards 0.2s"));
		
		function res($obj,maxs,cb){
			top=$obj.offset().top;
			diff=scrollTop+height-top;

			if(diff>maxs) cb();
		}
		
		function res_2(){
			web.tit_2_Id.css(com.animatStyle("tit_1 1.6s cubic-bezier(.1,0,.04,1) forwards"));
			web.img_2_Id.css(com.animatStyle("img_1 1.6s cubic-bezier(.1,0,.04,1) forwards"));
			
			web.data.swich_2=false;
		}
		
		function res_3(){
			web.tit_3_Id.css(com.animatStyle("tit_1 1.6s cubic-bezier(.1,0,.04,1) forwards"));
			web.img_3_Id.css(com.animatStyle("img_1 1.6s cubic-bezier(.1,0,.04,1) forwards"));
			
			web.data.swich_3=false;
		}
		
		function res_4(){
			web.tit_4_Id.css(com.animatStyle("tit_1 1.6s cubic-bezier(.1,0,.04,1) forwards"));
			web.img_4_Id.css(com.animatStyle("img_1 1.6s cubic-bezier(.1,0,.04,1) forwards"));
			
			web.data.swich_4=false;
		}
		
		function res_5(){
			web.tit_5_Id.css(com.animatStyle("tit_1 1.6s cubic-bezier(.1,0,.04,1) forwards"));
			web.img_5_Id.css(com.animatStyle("img_1 1.6s cubic-bezier(.1,0,.04,1) forwards"));
			
			web.data.swich_5=false;
		}
		
		function res_6(){
			web.tit_6_Id.css(com.animatStyle("tit_1 1.6s cubic-bezier(.1,0,.04,1) forwards"));
			web.img_6_Id.css(com.animatStyle("img_1 1.6s cubic-bezier(.1,0,.04,1) forwards"));
			
			web.data.swich_6=false;
		}
		
		function res_7(){
			web.tit_7_Id.css(com.animatStyle("tit_1 1.6s cubic-bezier(.1,0,.04,1) forwards"));
			web.img_7_Id.css(com.animatStyle("img_1 1.6s cubic-bezier(.1,0,.04,1) forwards"));
			
			web.data.swich_7=false;
		}
		
		function res_8(){
			web.tit_8_Id.css(com.animatStyle("tit_1 1.6s cubic-bezier(.1,0,.04,1) forwards"));
			web.img_8_Id.css(com.animatStyle("img_1 1.6s cubic-bezier(.1,0,.04,1) forwards"));
			
			web.data.swich_8=false;
		}
	}
};